home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 573 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.1 KB

  1. From: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
  2. Message-ID: <4h0lo0$q0f@mulga.cs.mu.OZ.AU>
  3. X-Original-Date: 28 Feb 1996 04:29:52 GMT
  4. Path: in2.uu.net!bounce-back
  5. Date: 28 Feb 96 07:25:11 GMT
  6. Approved: fjh@cs.mu.oz.au
  7. Newsgroups: comp.std.c++
  8. Subject: Re: Q: default constructor for fundamental types?
  9. Organization: Comp Sci, University of Melbourne
  10. References: <4glrdc$dqo@ra.ibr.cs.tu-bs.de> <4gsvhn$csi@clarknet.clark.net> <9602271131.AA18225@lts.sel.alcatel.de> <4gvte1$qvd@xanadu.io.com>
  11. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  12.     iQBFAgUBMTQEWeEDnX0m9pzZAQFJ/wF9HQY6cEzsjA3pzACiX7+Hd1oRkuv7+SoU
  13.     J12TSvbUrkCGlawzDV5jFeSFK8b8Unx7
  14.     =tfEi
  15.  
  16. jamshid@io.com (Jamshid Afshar) writes:
  17.  
  18. >James Kanze <kanze@lts.sel.alcatel.de> wrote:
  19. >>Expressions of the form `int()' have always been allowed.  A (fairly)
  20. >>recent change to the draft standard states that they have the same
  21. >>value as default static initialization (in this case, 0).  The earlier
  22. >>rules had the initailization undefined.
  23. >
  24. >Is the following legal?
  25. >
  26. >    class Foo {
  27. >       int x;
  28. >    public:
  29. >       Foo()
  30. >         : x()   // legal?
  31. >       {}
  32. >    };
  33.  
  34. Yes.
  35.  
  36. >and if so is it different than just:
  37. >
  38. >    Foo::Foo() {}
  39.  
  40. Yes, they are different.  The former is equivalent to
  41.  
  42.     Foo::Foo() : x(0) {}
  43.  
  44. This can be deduced from the following sections of the working paper:
  45.  
  46.     [class.base.init] 12.6.2/3
  47.         "if the *expression-list* of the *mem-initializer* is
  48.         omitted, the base class or member subobject is
  49.         default-initialized (see [dcl.init])"
  50.  
  51.     [dcl.init] 8.5/5
  52.         "To default-initialize an object of type T means:
  53.         --if T is a non-POD class type ...;
  54.         --if T is an array type ...;
  55.         --otherwise, the storage for the object is zero-initialized."
  56.  
  57. --
  58. Fergus Henderson                 WWW: http://www.cs.mu.oz.au/~fjh
  59. fjh@cs.mu.oz.au                  PGP: finger fjh@128.250.37.3
  60. ---
  61. [ To submit articles: try just posting with your news-reader.
  62.                       If that fails, use mailto:std-c++@ncar.ucar.edu
  63.   FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
  64.   Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
  65.   Comments? mailto:std-c++-request@ncar.ucar.edu.
  66. ]
  67.